(function(){"use strict";BX.namespace("BX.UI");BX.UI.Pinner=function(t,o){this.node=t;this.options=o||{};if(typeof this.options.pinTop==="undefined"&&typeof this.options.pinBottom==="undefined"){this.options.pinTop=true;this.options.pinBottom=true}else{this.options.pinTop=!!this.options.pinTop;this.options.pinBottom=!!this.options.pinBottom}this.options.fixTop=!!this.options.fixTop;this.options.fixBottom=!!this.options.fixBottom;this.options.initialWidth=t.style.width;this.init()};BX.UI.Pinner.prototype={node:null,options:{},timeout:0,classUi:"ui-pinner",classTop:"ui-pinner-top",classBottom:"ui-pinner-bottom",classFullWidth:"ui-pinner-full-width",init:function(){var t=this.node;var o=this.options;var i;if(!o.anchorTop){var n=document.createElement("div");t.parentNode.insertBefore(n,t);o.anchorTop=n}if(document.querySelector(o.anchorBottom)){i=document.querySelector(o.anchorBottom);o.anchorBottom=i}else{i=document.createElement("div");t.parentNode.insertBefore(i,t.nextSibling);o.anchorBottom=i}BX.bind(window,"scroll",BX.throttle(this.onChange.bind(this),200));BX.bind(window,"resize",BX.throttle(this.onChange.bind(this),this.timeout));this.onChange()},onChange:function(){var t=this.node;var o=this.options;var i;if(this.options.fixBottom||this.options.pinTop&&this.isNodeOnScreenBottom(o.anchorBottom)){this.applyNodeWidth();BX.removeClass(t,this.classTop);BX.addClass(t,this.classUi);BX.addClass(t,this.classBottom);i=BX.pos(t);o.anchorBottom.style.height=0;o.anchorBottom.style.height=i.height+"px"}else if(this.options.fixTop||this.options.pinTop&&this.isNodeOnScreenTop(o.anchorTop)){this.applyNodeWidth();BX.removeClass(t,this.classBottom);BX.addClass(t,this.classUi);BX.addClass(t,this.classTop);i=BX.pos(t);o.anchorTop.style.height=0;o.anchorTop.style.height=i.height+"px"}else{BX.removeClass(t,this.classTop);BX.removeClass(t,this.classBottom);BX.removeClass(t,this.classUi);t.style.width=o.initialWidth?o.initialWidth:null;o.anchorTop.style.height=0;o.anchorBottom.style.height=0}},applyNodeWidth:function(){if(this.options.fullWidth){BX.addClass(this.node,this.classFullWidth);return}var t=this.options.anchorTop||this.options.anchorBottom;var o=t.getBoundingClientRect();this.node.style.width=o.width+"px"},isNodeOnScreenTop:function(t){var o=this.getCoordinates(t);return o.top<o.windowTop&&o.bottom<o.windowBottom},isNodeOnScreenBottom:function(t){var o=this.getCoordinates(t);return o.bottom>o.windowBottom&&o.top>o.windowTop||document.documentElement.scrollHeight-t.scrollHeight<40},getCoordinates:function(t){var o=t.getBoundingClientRect();var i=o.top+window.pageYOffset;var n=window.pageYOffset||document.documentElement.scrollTop;return{windowTop:n,windowBottom:n+document.documentElement.clientHeight,top:i,bottom:i+t.offsetHeight,left:o.left+window.pageXOffset,width:o.width}}}})();
//# sourceMappingURL=ui.pinner.map.js